package com.zcb.agrimarket.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcb.agrimarket.mapper.LabMapper;
import com.zcb.agrimarket.pojo.Arrange;
import com.zcb.agrimarket.pojo.Lab;
import com.zcb.agrimarket.pojo.StudentApplyLog;
import com.zcb.agrimarket.pojo.User;
import com.zcb.agrimarket.result.Result;
import com.zcb.agrimarket.service.ArrangeService;
import com.zcb.agrimarket.service.StudentApplyLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/StudentApply")
@Api(tags = "学生申请教室相关接口")
@Slf4j
@CrossOrigin//$$$用于处理跨域问题
public class StudentApplyController {

    @Autowired
    StudentApplyLogService studentApplyLogService;

    @Autowired
    ArrangeService arrangeService;


    @GetMapping
    @ApiOperation("学生查询可申请的教室")
    public Result<ArrayList<StudentApplyLog>> get(Integer page, Integer pageSize, Long semesterId, Integer week, Integer day, Integer session, Long labType){
        ArrayList<StudentApplyLog>  studentApplyLogArrayList = studentApplyLogService.selectList(page,pageSize,semesterId,week,day,session,labType);
        return Result.success(studentApplyLogArrayList);
    }

    /**
     * 学生查询其本人的所有教室申请
     * TODO：后续添加JWT验证，从JWT中获取学生ID，并添加到条件中
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/studentApply")
    @ApiOperation("学生查询本人的教室申请")
    public Result<Page> getAll(Integer page, Integer pageSize){
        log.info("当前页码：{}",page);
        log.info("页面大小：{}",pageSize);
        //构造分页构造器
        Page pageInfo = new Page(page,pageSize);

        //构造条件构造器
        LambdaQueryWrapper<StudentApplyLog> queryWrapper = new LambdaQueryWrapper();

        //执行查询
        studentApplyLogService.page(pageInfo,queryWrapper);

        return Result.success(pageInfo);
    }

    /**
     * 在studentApplyLog表中进行一个插入
     * @param studentApplyLog
     * @return
     */
    @PostMapping
    @ApiOperation("学生申请教室")
    public Result save(@RequestBody StudentApplyLog studentApplyLog){
        studentApplyLogService.save(studentApplyLog);
        return Result.success("提交教室申请");
    }

    /**
     * 只能修改状态信息
     * @param studentApplyLog
     * @return
     */
    @PutMapping
    @ApiOperation("修改申请信息")
    public Result<String> updata(@RequestBody StudentApplyLog studentApplyLog){
        studentApplyLogService.update(studentApplyLog);
        return  Result.success("成功修改申请信息！");
    }
}
